package everyday;

import CommonStructure.ListNode;

import java.util.HashMap;

/**
 * @Author: Siantar
 * @Date: 2023-06-11-20:28
 * @Description: 1.0
 */
public class T1171 {
    public ListNode removeZeroSumSublists(ListNode head) {
        ListNode t = new ListNode(0);
        t.next = head;
        HashMap<Integer, ListNode> map = new HashMap<>();
        int sum = 0;
        for (ListNode p = t; p != null; p = p.next) {
            sum += p.val;
            map.put(sum, p);
        }
        sum = 0;
        for (ListNode p = t; p != null; p = p.next) {
            sum += p.val;
            p.next = map.get(sum).next;
        }
        return t.next;
    }
}
